<menu:UserControl x:Class="Rage.UI.ItemListControl"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:menu="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:controls="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:local="clr-namespace:Rage.UI"
  mc:Ignorable="d"
  Height="500" Width="365">

  <menu:UserControl.Resources>
    <menu:ItemsPanelTemplate x:Key="ItemsPanelTemplateItemModTypesRatings">
      <menu:StackPanel Orientation="Horizontal" />
    </menu:ItemsPanelTemplate>
    <menu:DataTemplate x:Key="DataTemplateItemModTypes">
      <menu:Grid Margin="1" Background="{Binding SocketBrush}" VerticalAlignment="Center">
        <menu:Image Height="24" Margin="1" Width="24" Source="{Binding ModIcon}" />
      </menu:Grid>
    </menu:DataTemplate>
    <menu:DataTemplate x:Key="DataTemplateRatings">
      <menu:Rectangle Width="{Binding Width}" Fill="{Binding Brush}" VerticalAlignment="Stretch" Visibility="{Binding Visibility}" />
    </menu:DataTemplate>
    <menu:DataTemplate x:Key="DataTemplateListBoxItemsItem">
      <menu:Grid>
        <menu:StackPanel IsHitTestVisible="False" Orientation="Vertical">
          <menu:DockPanel HorizontalAlignment="Stretch" LastChildFill="True">
            <menu:Image Margin="0,0,2,0" MaxHeight="32" MaxWidth="32" Source="{Binding Icon}" menu:DockPanel.Dock="Left" />
            <menu:ItemsControl x:Name="DataTemplateListBoxItemsControl"  ItemsPanel="{StaticResource ItemsPanelTemplateItemModTypesRatings}" ItemsSource="{Binding Mods}" ItemTemplate="{StaticResource DataTemplateItemModTypes}" menu:DockPanel.Dock="Right">
            </menu:ItemsControl>
            <menu:TextBlock Margin="1" HorizontalAlignment="Stretch" Text="{Binding Name}" TextWrapping="Wrap" VerticalAlignment="Center" />
          </menu:DockPanel>
          <menu:ItemsControl Height="2" Margin="0,2,0,0" HorizontalAlignment="Stretch" ItemsPanel="{StaticResource ItemsPanelTemplateItemModTypesRatings}" ItemsSource="{Binding Ratings}" ItemTemplate="{StaticResource DataTemplateRatings}">
          </menu:ItemsControl>
        </menu:StackPanel>
        <menu:Rectangle Margin="-2" Fill="Transparent" HorizontalAlignment="Stretch" MouseEnter="item_MouseEnter" MouseLeave="item_MouseLeave" MouseLeftButtonUp="item_Clicked" MouseRightButtonUp="Rectangle_MouseRightButtonUp" VerticalAlignment="Stretch">
          <menu:ContextMenuService.ContextMenu>
            <menu:ContextMenu x:Name="ContextMenuItem" Opened="ContextMenuItem_Opened">
              <!--<menu:MenuItem x:Name="ContextItemName" IsEnabled="False" Header="Super Cool Item"/>
              <menu:Separator/>-->
              <menu:MenuItem x:Name="ContextEdit" Click="EditItem" Header="Edit..." />
              <menu:MenuItem x:Name="ContextOpenTorhead" Click="OpenInTorhead" Header="Open in Knotor" />
              <!--<menu:MenuItem x:Name="ContextRefreshArmory" Header="Refresh Item from Armory" Click="RefreshItemFromArmory" Visibility="Collapsed"/>-->
              <menu:MenuItem x:Name="ContextRefreshTorhead" Click="RefreshItemFromTorhead" Header="Refresh Item from Torhead" />
              <!--<menu:MenuItem x:Name="ContextEquip" Header="Equip" Click="EquipItem"/>-->
              <!--<menu:MenuItem x:Name="ContextAddCustom" Header="Add Custom ItemModTypeming..." Click="AddCustomItemModTypeming" Visibility="Collapsed"/>-->
              <!--<menu:MenuItem x:Name="ContextDeleteCustom" Header="Delete Custom ItemModTypeming" Click="DeleteCustomItemModTypeming" Visibility="Collapsed"/>-->
              <!--<menu:MenuItem x:Name="ContextEvaluateUpgrade" Header="Evaluate Upgrade..." Click="EvaluateUpgrade"/>-->
              <!--<menu:MenuItem x:Name="ContextEvaluateUpgradesBySlot" Header="Evaluate Upgrades for this Slot..." Click="EvaluateUpgradesbySlot"/>-->
              <!--<menu:MenuItem x:Name="ContextRemoveItemFromUpgradeList" Header="Remove Item from Upgrade List" Click="ContextRemoveItemFromUpgradeList_Click"/>-->
            </menu:ContextMenu>
          </menu:ContextMenuService.ContextMenu>
        </menu:Rectangle>
      </menu:Grid>
    </menu:DataTemplate>
  </menu:UserControl.Resources>

  <menu:Grid Margin="-10000,-10000,-10000,-10000" Background="#00000000" IsHitTestVisible="True" MouseLeftButtonDown="Background_MouseLeftButtonDown">
    <menu:Border Margin="10000,10000,10000,10000" BorderBrush="DarkGray" BorderThickness="1" CornerRadius="2">
      <menu:Grid>
        <menu:Grid.RowDefinitions>
          <menu:RowDefinition Height="26" />
          <menu:RowDefinition />
        </menu:Grid.RowDefinitions>
        <menu:DockPanel LastChildFill="True">
          <menu:DockPanel.Background>
            <menu:LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
              <menu:GradientStop Color="#FFDEDEDE" Offset="1" />
              <menu:GradientStop Color="#FFFFFFFF" Offset="0" />
            </menu:LinearGradientBrush>
          </menu:DockPanel.Background>
          <menu:TextBlock Margin="4,2,2,2" Text="Filter: " VerticalAlignment="Center" menu:DockPanel.Dock="Left" />
          <menu:ComboBox x:Name="comboBoxSort" Margin="2" SelectionChanged="comboBoxSort_SelectionChanged" VerticalAlignment="Center" menu:DockPanel.Dock="Right" />
          <menu:TextBlock Margin="2,2,6,2" Text="Sort: " VerticalAlignment="Center" menu:DockPanel.Dock="Right" />
          <menu:TextBox x:Name="textBoxFilter" Margin="2" Text="{Binding Path=Items.Filter, Mode=TwoWay}" TextChanged="Filter_TextChanged" VerticalAlignment="Center" />
        </menu:DockPanel>
        <menu:ListBox x:Name="listBoxItems" Grid.Row="1" ScrollViewer.VerticalScrollBarVisibility="Visible" BorderThickness="0" ItemsSource="{Binding Items}" ItemTemplate="{StaticResource DataTemplateListBoxItemsItem}" MouseWheel="listBoxItems_MouseWheel" SelectionChanged="listBoxItems_SelectionChanged">
          <menu:ListBox.ItemContainerStyle>
            <menu:Style TargetType="ContentControl">
              <menu:Setter Property="HorizontalContentAlignment" Value="Stretch" />
              <menu:Setter Property="MaxWidth" Value="344" />
            </menu:Style>
          </menu:ListBox.ItemContainerStyle>
        </menu:ListBox>
      </menu:Grid>
    </menu:Border>
  </menu:Grid>
</menu:UserControl>